using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sfcms.api;

public partial class sfcms_sfcms_download : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        long fileID;
        if (!long.TryParse(Request.QueryString["id"].ToString(), out fileID)) return;
        file f = file.fromid(fileID);
        if (f == null) return;
        
        Response.ContentType = f.contenttype;
        Response.AddHeader("content-disposition", "attachment;filename=" + f.filename + "." + f.fileextension);

        if (f.isimage)
        {
            if (Request.QueryString["th"] == "1")
            {
                Response.BinaryWrite(f.thumbnaildata);
                return;
            }
        }
        Response.BinaryWrite(f.data);
    }
}
